package com.wuxinwudai.android.app;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

/**
 * BaseApplication 类为 Android 应用程序基类
 * @author 吾心无待
 *
 */
public class BaseApplication extends Application{
	private static BaseApplication mApplication;
	private static Context mContext;

	/**
	 * 构造函数，初始化 BaseApplication 类的一个新实例
	 */
	public BaseApplication(){
		mApplication = this;
	}

	/**
	 * 获取默认唯一的 Application 实例
	 * @return Application 实例
     */
	public static BaseApplication getApplication(){
		return mApplication;
	}

	@Override
	public void onCreate(){
		super.onCreate();	
		mContext = getApplicationContext();
	}

	/**
	 * 静态方法获取 ApplicationContext 对象
	 * @return ApplicationContext 对象
	 */
	public static Context getContext(){
		return mContext;
	}

   	@Override
	public void onLowMemory() {
		super.onLowMemory();
		System.gc();
	}

	/**
	 * 退出应用程序
	 */
	public void exit(){
		try{
			ActivityCollector.finishAll();
			ActivityManager activityManager  = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
			activityManager.restartPackage(mContext.getPackageName());
		}catch (Exception ex){

		}
	}
}
